
local locplayer = ac.player.self
local w,h = 280,180


local ui = class.panel:builder 
{
    x = 0,
    y = 620,
    w = w,
    h = h,
    alpha = 0.99,
    level = 99,
    fdf = 'tooltip_backdrop0',
    show_flag = false,
}
ui.title = ui:add_text('|cffffff00天赋表|r',0,5,nil,30,12,5)


local w1,h1 = 64,64
local x1 = 10
local y1 = 40
ui.buttons = {}
for a=1,2 do
    for b=1,4 do
        local x = (b-1) * (w1 + 1) + x1
        local y = (a-1) * (h1 + 1) + y1
        local panel = ui:add_card_button(x,y,w1,h1)
        table.insert(ui.buttons,panel)
    end
end

--离开
ui.show_time = 0

local empty = {}
function ui:update(frame)
    local hero = locplayer.hero
    local data = hero and hero._card_list or empty
    for i,button in ipairs(self.buttons) do
        local skill = data[i]
        button:set_data(skill)
    end
    
end

function ui:on_button_mouse_enter(button)
    local skill = button.skill
    if skill then
        local ui = button:tooltip(skill:get_title(),skill:get_tip(),'right')
        self:set_tooltip_follow(ui, 'right',0,-(self.h-ui.h)/2)
    end
end

-- ac.game:event '动画-抽卡显示'(function(_,art,point,index)
--     local button = ui.buttons[index]
--     local x,y = button:get_real_position()
--     local target = {x,y,button.w,button.h}
--     local tween = ac.tween('outBack', 3,point,target)
--     ac.game:notify('动画-播放拖动',art,tween)
-- end)


local button = ui:add_button('',0,0,nil,35)
button.drag_flag = true

function button:on_button_mouse_down()
    local x,y = ac.hardware:get_mouse_pos()
    self.start_x = x
    self.start_y = y
end

function button:on_button_drag(x,y)
    ui:set_position(ui.x + x - self.start_x,ui.y + y - self.start_y)
    self.start_x = x
    self.start_y = y
end

ac.game:notify('游戏-注册显示UI',ui)

return ui